package cn.etynit.controller;

import cn.etynit.domain.User;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
@RefreshScope  // 打开动态刷新配置注解
public class UserController {

//    @Value("${test.name}")
//    private String name;

    @GetMapping("/{id}")
    @SentinelResource(value = "getUserById",blockHandler = "getUserByIdBlockHandler")
    public User getUserById(@PathVariable("id") Long id){
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return new User(id, "王日怪", "我在等风，也在等你！");
    }

    public User getUserByIdBlockHandler(@PathVariable("id") Long id, BlockException blockException){
        blockException.printStackTrace();
        return new User(id, "王日怪2325312536123", "我在等风，也在等你！");
    }
}
